package com.year_23.april;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * 2404 出现最频繁的偶数元素
 * @Author jsh
 * @Date 2023/4/16 22:58
 * @Version 1.0
 */
public class Day13 {

    public int mostFrequentEven(int[] nums){
        Map<Integer,Integer> map = new HashMap<Integer,Integer>();
        for (int i : nums){
            if (i % 2 == 0){
                map.put(i, map.containsKey(i) ? map.get(i) + 1 : 1);
            }
        }
        int res = -1;
        int resValue = 0;
        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
            if (res == -1 || resValue < entry.getValue() || (resValue == entry.getValue() && res > entry.getKey())){
                res = entry.getKey();
                resValue = entry.getValue();
            }
        }

        return res;
    }
}
